import {ImageAsset, Texture2D, SpriteFrame, Sprite} from "cc"
import {oops} from "db://oops-framework/core/Oops";
// 将 imageAsset 转换为SpriteFrame
export function imageAsset2Sprite(icon: ImageAsset): SpriteFrame {
    const texture = new Texture2D();
    texture.image = icon;
    const spriteFrame = new SpriteFrame();
    spriteFrame.texture = texture;
    return spriteFrame
}

// 下载图片
export function downloadImage(url: string, spriteNode: Sprite) {
    oops.res.loadRemote(url, (err: Error, data: ImageAsset) => {
        if (err != null) {
            // 下载失败
            console.error(err)
            return;
        }
        spriteNode.spriteFrame = imageAsset2Sprite(data)
    })
}